package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.ConfirmAnOrderResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.app.util.Util
import com.gexiaobao.pigeon.databinding.ItemConfirmOrderBinding
import com.makeramen.roundedimageview.RoundedImageView

/**
 * @author: hxw
 * @date  : 2023/2/2
 * @desc  :
 */
class OrderDetailGoodsAdapter(data: ArrayList<ConfirmAnOrderResponse.StoreInfoList.GoodsOrderList>) :
    BaseQuickAdapter<ConfirmAnOrderResponse.StoreInfoList.GoodsOrderList, DataBindBaseViewHolder>(R.layout.item_confirm_order, data) {

    private var onBtnReturnClickListener: OnBtnReturnClickListener? = null

    @SuppressLint("SetTextI18n")
    override fun convert(holder: DataBindBaseViewHolder, item: ConfirmAnOrderResponse.StoreInfoList.GoodsOrderList) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemConfirmOrderBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val itemGoodsImage = holder.getView<RoundedImageView>(R.id.ivItemGoodsImage)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.specImg, itemGoodsImage, 10, R.drawable.shop_product_def)

        val tvPrice = holder.getView<AppCompatTextView>(R.id.itemPrice)
        val totalPrice = Util.mul(item.salePrice.toString(), item.amount.toString())
        SettingUtil.setPrice(totalPrice, tvPrice, 50, Color.BLACK)

        holder.getView<AppCompatTextView>(R.id.tvItemReturnGoods).setOnClickListener {
            onBtnReturnClickListener?.onItemClick(holder.layoutPosition)
        }

        when (item.childOrderStatus) {
            2 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.refund))//"退款"
            }

            3 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.sales_return))//"退货"
            }

            4 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.Return_after_sales))//"售后/退货"
            }

            7 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.refund_successful))//"退款成功"
            }

            11, 13, 14 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.Return_details))//"退货详情"
            }

            15 -> {
                holder.setGone(R.id.tvItemReturnGoods, false)
                holder.setText(R.id.tvItemReturnGoods, context.getString(R.string.out_information))//"我已寄出"
            }

            else -> {
                holder.setGone(R.id.tvItemReturnGoods, true)
            }
        }
    }

    fun setOnReturnGoodsClickListener(listener: OnBtnReturnClickListener?) {
        onBtnReturnClickListener = listener
    }

    interface OnBtnReturnClickListener {
        fun onItemClick(position: Int)
    }
}